public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();

        Thread thread = new Thread(() -> {
            synchronized(locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread.start();
        thread.join(1000);
        synchronized(locker) {
            locker.notify();
        }
    }
}
